<?php defined('_JEXEC') or die('Restricted access'); ?>
<script language="javascript" type="text/javascript">
	function doSubmit(form, task) {
		if (form) {
			form.task.value = task;
			form.submit();
		}
	}

	function checkForm() {
		var countryid = document.getElementById('countryid').selectedIndex;
		if (countryid == -1) {
			alert('You must choose a country first');
			return false;
		}
		return true;
	}

	function submitForm(form, task) {
		if (!checkForm()) return false;
		doSubmit(form, task);
	}
</script>
<table class="contentpaneopen">
	<tbody>
		<tr>
			<td class="contentheading"><?php echo JText::_('My Golf Scorecard'); ?></td>
		</tr>
	</tbody>
</table>

<div>
	<input type="button" class="button" value="<?php echo JText::_('Add Course'); ?>" onclick="document.location.href='index.php?option=com_scorecard&view=course&Itemid=<?php echo $this->itemid; ?>'"/>
	<input type="button" class="button" value="<?php echo JText::_('Add Score'); ?>" onclick="document.location.href='index.php?option=com_scorecard&view=scorecard&Itemid=<?php echo $this->itemid; ?>'"/>
</div>

<div class="scoresearch_container">
<div class="scoresearch">
	<form action="" method="post" name="scoreform">
		<div class="scorecard_box" style="height:235px">
			<h3>Score Search</h3>
			<table cellpading="0" cellspacing="0">
				<tbody>
					<tr>
						<td style="width:130px"><?php echo JText::_('Select Country:'); ?></td>
						<td>
							<?php if($this->country):?>
								<?php echo $this->country; ?>
							<?php endif; ?>
						</td>
					</tr>

					<tr>
						<td><?php echo JText::_('Select State:'); ?></td>
						<td>
							<?php if($this->state):?>
								<?php echo $this->state; ?>
							<?php endif; ?>
						</td>
					</tr>

					<tr>
						<td><?php echo JText::_('Select Golf Course:'); ?></td>
						<td>
							<?php if($this->course):?>
								<?php echo $this->course; ?>
							<?php endif; ?>
						</td>
					</tr>

					<tr>
						<td><?php echo JText::_('From Date:'); ?></td>
						<td>
							<?php echo JHTML::_('calendar', $this->fromdate, 'fromdate', 'fromdate', '%d-%m-%Y', array('class'=>'dateinput', 'maxlength'=>'19')); ?>
						</td>
					</tr>

					<tr>
						<td><?php echo JText::_('To Date:'); ?></td>
						<td>
							<?php echo JHTML::_('calendar', $this->todate, 'todate', 'todate', '%d-%m-%Y', array('class'=>'dateinput', 'maxlength'=>'19')); ?>
						</td>
					</tr>

					<tr>
						<td></td>
						<td>
							<input type="button" class="button" value="Clear" onclick="doSubmit(this.form, 'resetForm')"/>
							<input type="button" class="button" value="Search" onclick="submitForm(this.form, 'scoreSearch')"/>
						</td>
					<tr>
				</tbody>
			</table>
		</div>
		<input type="hidden" name="option" value="<?php echo $option; ?>"/>
		<input type="hidden" name="task" value=""/>
		<input type="hidden" name="view" value="score"/>

</div>

<div class="statistics">
	<div class="scorecard_box" style="height:235px">
		<h3><?php echo JText::_('Statistics'); ?></h3>
		<p>
			<?php if (isset($this->handicap) && $this->handicap != 9999): ?>

				<?php echo JText::_('Your unoffical Handicap:'); ?>
				<br>
				<div class="handicap"><?php echo $this->handicap; ?></div>
			<?php else: ?>
				<?php echo JText::_('You need a minimum of 5 scorecards to calculate a handicap score.'); ?>
			<?php endif; ?>
		</p>

	</div>
</div>
</div>

<?php if (JRequest::getVar('task') == 'scoreSearch'): ?>
	<?php if(count($this->scores) <= 0): ?>
			<div class="scorecard_errorbox">
				No item found. Redefine your criterias and try again!
			</div>
			<br>
	<?php else: ?>
		<table class="contentpaneopen">
			<tbody>
				<tr>
					<td class="contentheading"><?php echo JText::_('Search Results'); ?></td>
				</tr>
			</tbody>
		</table>
		
		<div>
			<table class="result">
				<tr>
					<th style="width: 100px">Date</th>
					<th>Golf Course</th>
					<th style="width: 60px">Par</th>
					<th style="width: 60px">Score</th>
				</tr>
				<?php foreach($this->scores as $score): ?>
					<tr>
						<td><?php echo $score['playdate']; ?></td>
						<td><?php echo $score['name']; ?></td>
						<td><?php echo $score['par']; ?></td>
						<td><?php echo $score['score']; ?></td>
					</tr>
				<?php endforeach; ?>
			</table>
		</div>
		
		<?php if ($this->pagination): ?>
			<?php echo $this->pagination->render(); ?>
		<?php endif; ?>
		
	<?php endif; ?>
<?php endif; ?>
</form>




